import { _decorator, Component, Node, v3 } from 'cc';
import { EnemyBossDt } from '../../../FrameWork3.8.6/FrameWork/Common/CommonInterface';
import { CharacterBase } from '../Base/CharacterBase';
const { ccclass, property } = _decorator;

@ccclass('EnemyBoss')
export class EnemyBoss extends CharacterBase {
    private _enemyBossDt:EnemyBossDt=null;

    private _dirX:number=-50;
    
    private _endPosX=-900;
    get enemyBossDt(){
        return this._enemyBossDt;
    }
    lateInit(...rest: any[]): void {
        this._enemyBossDt=rest[0]as EnemyBossDt;
    }


    onUpdate(dt:number){
        //判断攻击范围是否有敌人
        this.searchEnemy();
        if(this._arrEnemy.length){
            let target=this.getNearestCamp();
            if(!target){
                return;
            }
            this.attack(target);
            return;
        }
        //当前范围没有敌人，兵种向endPos的x前进,播放移动动画
        this.walk();
        if(this.node.position.x<=this._endPosX){
            this.node.setPosition(v3(this._endPosX,this.node.position.y));
            return;
        }
        let moveX=dt*this.enemyBossDt.speed*this._dirX;
        this.node.setPosition(v3(this.node.position.x+moveX,this.node.position.y));
    }

   
}


